package com.zjk.storage.core.aspect.download;


import com.zjk.storage.core.aspect.FileStorageAspect;
import com.zjk.storage.core.entity.BaseFileInfo;
import com.zjk.storage.core.provider.FileStorage;
import lombok.Getter;
import lombok.Setter;

import java.io.InputStream;
import java.util.Iterator;
import java.util.function.Consumer;

@Getter
@Setter
public class DownloadThumbAspectChain {
    private DownloadThumbAspectChainCallback callback;
    private Iterator<FileStorageAspect> aspectIterator;
    public void run(DownloadThumbAspectChainCallback callback, Iterable<FileStorageAspect> aspects) {
        this.callback = callback;
        aspectIterator = aspects.iterator();
    }
    public void next(BaseFileInfo fileInfo, FileStorage fileStorage, Consumer<InputStream> consumer) {
        if (aspectIterator.hasNext()) {
            aspectIterator.next().downloadThumbAround(fileInfo, fileStorage, consumer, this);
        } else {
            callback.run(fileInfo, fileStorage, consumer);
        }
    }
}
